VERSION 5.00
Begin VB.Form frmLogin 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Login"
   ClientHeight    =   2565
   ClientLeft      =   7020
   ClientTop       =   2895
   ClientWidth     =   6270
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   2565
   ScaleWidth      =   6270
   WindowState     =   2  'Maximized
   Begin VB.CommandButton cmdExitLog 
      Caption         =   "Exit"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   840
      TabIndex        =   5
      Top             =   1920
      Width           =   1455
   End
   Begin VB.CommandButton cmdLog 
      Caption         =   "Login"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   3840
      TabIndex        =   4
      Top             =   1920
      Width           =   1455
   End
   Begin VB.TextBox txtPass 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   2400
      PasswordChar    =   "*"
      TabIndex        =   3
      Top             =   1200
      Width           =   2895
   End
   Begin VB.TextBox txtLogin 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2400
      TabIndex        =   2
      Top             =   600
      Width           =   2895
   End
   Begin VB.Label lblPass 
      AutoSize        =   -1  'True
      Caption         =   "Password"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   14.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   840
      TabIndex        =   1
      Top             =   1200
      Width           =   1260
   End
   Begin VB.Label lblLog 
      AutoSize        =   -1  'True
      Caption         =   "Login"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   14.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   840
      TabIndex        =   0
      Top             =   600
      Width           =   705
   End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Roles:
'  0 -> Manager
'  1 -> Technic
'  2 -> Dummy user


Private Sub cmdExitLog_Click()
    End
End Sub

Public Sub cmdLog_Click()
    If Me.txtLogin = "root" And Me.txtPass = "root" Then
        frmRoot.Show
    Else
        Dim connector As New ADODB.Connection
        Dim rs As New ADODB.Recordset
        Dim ok As Boolean
        ok = False
        connector.CursorLocation = adUseClient
        connector.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
        & "SERVER=127.0.0.1;" _
        & "DATABASE=incidences;" _
        & "UID=root;" _
        & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384
        connector.Open
        rs.ActiveConnection = connector
        rs.CursorType = adOpenDynamic
        rs.CursorLocation = adUseClient
        rs.LockType = adLockOptimistic
        rs.Open ("select * from users")
        While Not rs.EOF
            If rs.Fields(2).Value = Me.txtLogin And rs.Fields(3).Value = Me.txtPass Then
                ok = True
                If rs.Fields(0) = "0" Then
                    frmManager.Show
                Else
                    If rs.Fields(0) = "1" Then
                        frmTechnic.Show
                    Else
                        If rs.Fields(0) = "2" Then
                        frmDummy.Show
                        End If
                    End If
                End If
            End If
            rs.MoveNext
        Wend
        rs.Close
        connector.Close
        If ok = False Then
            MsgBox ("Wrong user/password")
        End If
    End If
End Sub

